# 设置默认JDK路径（根据实际安装路径修改）
$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jbr"

$targetDir = "$PSScriptRoot\..\android\app"
if (-not (Test-Path $targetDir)) {
    Write-Verbose "创建目标目录: $targetDir"
    New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}

if (Test-Path "$targetDir\mathfun-keystore.jks") {
    Write-Warning "密钥库文件已存在，正在更新..."
    Unblock-File -Path "$targetDir\mathfun-keystore.jks"
}


# 生成新密钥库
& "$env:JAVA_HOME\bin\keytool.exe" -genkeypair -v `
  -keystore "$targetDir/mathfun-keystore.jks" `
  -keyalg RSA `
  -keysize 2048 `
  -validity 10000 `
  -alias mathfun `
  -storepass 123456 `
  -keypass 123456 `
  -dname "CN=MathFun, OU=Android, O=btsyang, L=Shanghai, ST=SH, C=CN"